/*
 * Copyright (c) 2012, marco.tamburelli@gmail.com
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met: 
 * 
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer. 
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution. 
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * 
 * The views and conclusions contained in the software and documentation are those
 * of the authors and should not be interpreted as representing official policies, 
 * either expressed or implied, of the CometMI Project.
 */
package org.cometmi.gwt.server.events;

import org.cometmi.gwt.shared.exceptions.InvalidArgumentException;

/**
 * This is a method invocation event. Such events are normally fired when a
 * method form some object is invoked.
 * 
 * @author marco.tamburelli@gmail.com
 */
public interface MiEvent
{
	/**
	 * This method returns the object unique id.
	 * 
	 * @return The object id.
	 */
	String getObjectId();

	/**
	 * This method returns the idx'th parameter of the method.
	 * 
	 * @param clazz The java class or type used to translate the JavaScript
	 *        object into a java object.
	 * @param idx The index of parameter as it appear in the invocation.
	 * @return A provided parameter.
	 * @throws InvalidArgumentException
	 */
	<T> T getMethodArgument(Class<T> clazz, int idx) throws InvalidArgumentException;

	/**
	 * This method enables to set the idx'th parameter of the method. This has
	 * sense only before the method invocation; when the method has been invoked
	 * it will make no effect.
	 * 
	 * @param value The value which replace the old parameter.
	 * @param idx The index of parameter as it appear in the invocation.
	 * @throws InvalidArgumentException
	 */
	<T> void setMethodArgument(T value, int idx) throws InvalidArgumentException;

	/**
	 * When the flag is set to false the method will not be executed. It takes
	 * effect only before method execution.
	 * 
	 * @param enabled Tells if the method should be executed or not.
	 */
	void setEnabled(boolean enabled);

	/**
	 * This method returns true in case the method is enabled. The method status
	 * is, by default, enabled. Can be disabled only by invoking
	 * {@link MiEvent#setEnabled(boolean)}.
	 * 
	 * This method should be used in an implemented method
	 * {@link MiEventHandler#onAfterMethod(MiEvent)}.
	 * 
	 * @return The method status.
	 */
	boolean isEnabled();

	/**
	 * This method returns the queue event, generated by the queue receiving the
	 * call.
	 * 
	 * @return The event of type {@link QueueEvent}.
	 */
	QueueEvent getTargetQueueEvent();
}
